package o;

import android.content.Context;
import android.database.SQLException;
import android.text.TextUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class eud {
    private static List<String> ˊ = new ArrayList();
    private static List<cfr> ˋ = new ArrayList();
    private static int ˏ = 0;
    private final euc ॱ;

    public eud(euc o_euc, Context context) throws IOException {
        this.ॱ = o_euc;
    }

    public static int ˋ() {
        return ˏ + 105;
    }

    public static void ˊ(cfr o_cfr) {
        ˋ.add(o_cfr);
    }

    public static void ˋ(String str) {
        ˊ.add(str);
    }

    public void ˏ() throws SQLException {
        Logger.ˏ("DbUpdateHelper", "DbUpdateHelper initTables begin ");
        ॱ();
        ˎ();
        Logger.ˏ("DbUpdateHelper", "DbUpdateHelper initTables end ");
    }

    private void ˎ() {
        for (String str : ˊ) {
            if (TextUtils.isEmpty(str)) {
                Logger.e("DbUpdateHelper", "error tableName");
            } else if (this.ॱ.ˋ(str)) {
                Logger.ˎ("DbUpdateHelper", "DbUpdateHelper drop unused table " + str);
                this.ॱ.ˊ(str);
            }
        }
    }

    private void ॱ() throws SQLException {
        for (cfr o_cfr : ˋ) {
            String t_ = o_cfr.t_();
            if (this.ॱ.ˋ(t_)) {
                this.ॱ.ˏ(t_);
                Logger.ˏ("DbUpdateHelper", "DbUpdateHelpertableName exist moidfy table " + t_ + " successfully.");
                try {
                    this.ॱ.ˎ(o_cfr.K_());
                    ˊ(t_);
                    Logger.ˎ("DbUpdateHelper", "DbUpdateHelper insert data to table " + t_ + " successfully.");
                    this.ॱ.ॱ(t_);
                    Logger.ˎ("DbUpdateHelper", "DbUpdateHelperdrop table _temp_" + t_ + " successfully.");
                } catch (SQLException e) {
                    throw new SQLException("initTablesEx SQLException");
                }
            }
            Logger.ˏ("DbUpdateHelper", "DbUpdateHelper create table " + t_);
            try {
                this.ॱ.ˎ(o_cfr.K_());
            } catch (SQLException e2) {
                throw new SQLException("initTablesEx SQLException");
            }
        }
    }

    private void ˊ(String str) throws SQLException {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(" INSERT INTO ");
        stringBuilder.append(str);
        stringBuilder.append(" SELECT ");
        try {
            try {
                String ˋ = ˋ(this.ॱ.ॱॱ(str), this.ॱ.ॱॱ("_temp_" + str));
                if (ˋ != null) {
                    stringBuilder.append(ˋ);
                    stringBuilder.append(" FROM ");
                    stringBuilder.append("_temp_").append(str);
                    try {
                        this.ॱ.ˎ(stringBuilder.toString());
                        return;
                    } catch (SQLException e) {
                        throw new SQLException("DbUpdateHelper insertData mDbHelper.executeSQL error");
                    }
                }
                throw new NullPointerException("DbUpdateHelper insertData sInsertColumns is null. [tableName=" + str + "]");
            } catch (SQLException e2) {
                throw new SQLException("DbUpdateHelper insertData mDbHelper.getColumnNames error ");
            }
        } catch (SQLException e3) {
            throw new SQLException("insertData SQLException");
        }
    }

    private String ˋ(String[] strArr, String[] strArr2) {
        StringBuilder stringBuilder = new StringBuilder();
        ArrayList arrayList = new ArrayList();
        if (strArr2 != null) {
            List asList = Arrays.asList(strArr2);
        } else {
            Object obj = arrayList;
        }
        if (strArr == null || strArr.length <= 0 || strArr2 == null) {
            return null;
        }
        for (int i = 0; i < strArr.length; i++) {
            String str = strArr[i];
            if (asList.contains(str)) {
                stringBuilder.append(str);
            } else {
                stringBuilder.append("\"\"");
            }
            if (i != strArr.length - 1) {
                stringBuilder.append(',');
            }
        }
        return stringBuilder.toString();
    }
}
